import React from "react";
import {Pagination} from 'antd';

class pagination extends React.Component{

    constructor(props) {
        super(props);
        this.state = {
            pagination: {
                ...this.props.pagination
            }
        }
    }

    render() {

        const { total } = this.props,
              { pagination } = this.state;
        return <>
            <Pagination
                showSizeChanger
                pageSizeOptions={[5,10,15]}
                current={pagination.page}
                pageSize={pagination.limit}
                onChange={this.onPageChange.bind(this)}
                onShowSizeChange={this.onPageChange.bind(this)}
                showTotal={(total) => `共${total}条数据`}
                total={total}
            />
        </>
    }

    onPageChange (current, pageSize){
        this.setState({
            pagination: {
                page: current,
                limit: pageSize
            }
        }, () => {
            this.props.callback({
                page: current,
                limit: pageSize
            })
        })
    }
}

export default pagination
